# -*- coding: utf-8 -*-            
# @Author : chenliang
# @Time : 2024/3/19 14:27

from selenium.webdriver.common.by import By
from datetime import datetime, timedelta


class AdminOperationManagementLocator:
    # 等待转圈 [class="antd4-spin-dot antd4-spin-dot-spin"]
    wait = (By.CSS_SELECTOR, '[class="antd4-spin-dot antd4-spin-dot-spin"]')

    """
        operation management | Resource Compare Query
    """
    # operation management菜单
    operation_management_menu = (By.XPATH, '//div[contains(@data-menu-id,"OPERATION_MANAGEMENT_PLT")]/span')
    # operation management菜单是否打开  class="antd4-menu antd4-menu-sub antd4-menu-inline" 即为打开
    if_open_operation_management = (By.XPATH, '//div[contains(@data-menu-id,"OPERATION_MANAGEMENT_PLT")]/../ul')
    # Resource Compare Query菜单
    resource_compare_query_menu = (By.XPATH, '//div[text()="Resource Compare Query" and @class="cre-menu-layer-2"]')
    # Resource Compare Query 页面，Resource Compare Overview tab页面
    resource_compare_query_overview = (By.XPATH, '//*[text()="Resource Compare Overview"]')
    # Resource Compare Query 页面，Resource Compare Log tab页面
    resource_compare_query_log = (By.XPATH, '//*[text()="Resource Compare Log"]')
    # Resource Compare Overview tab页面的result数据项点击
    button_result = (By.XPATH, '//*[text()="Result"]/..//span[@role="button"]')
    # Resource Compare Log tab页面的result数据项点击
    button_result1 = (By.XPATH, '(//*[text()="Result"]/..//span[@role="button"])[2]')
    # result 点开后待选择的数据项, class="antd4-dropdown-menu-item antd4-dropdown-menu-item-selected" 被选择
    result_list = (By.XPATH, '//*[@class="antd4-dropdown-menu-title-content"]/..')

    # 查询列表Instance ID 数据
    def get_list_instance_id(tab, num=1):
        # num =1 时获取列表第一条数据的Instance ID
        if num == 1:
            context = '((//*[@class="antd4-table-tbody"])[' + tab + ']//tr[@class="antd4-table-row antd4-table-row-level-0"]/td[1]/div)[1]'
        else:
            context = '(//*[@class="antd4-table-tbody"])[' + tab + ']//tr[@class="antd4-table-row antd4-table-row-level-0"]/td[1]/div'
        return (By.XPATH, context)

    # 查询列表organization 数据
    def get_list_organization(tab, num=1):
        if tab == '2':
            # num =1 时获取列表第一条数据的organization
            if num == 1:
                context = '((//*[@class="antd4-table-tbody"])[' + tab + ']//tr[@class="antd4-table-row antd4-table-row-level-0"]/td[8]/div)[1]'
            else:
                context = '(//*[@class="antd4-table-tbody"])[' + tab + ']//tr[@class="antd4-table-row antd4-table-row-level-0"]/td[8]/div'
        else:
            # num =1 时获取列表第一条数据的organization
            if num == 1:
                context = '((//*[@class="antd4-table-tbody"])[' + tab + ']//tr[@class="antd4-table-row antd4-table-row-level-0"]/td[9]/div)[1]'
            else:
                context = '(//*[@class="antd4-table-tbody"])[' + tab + ']//tr[@class="antd4-table-row antd4-table-row-level-0"]/td[9]/div'
        return (By.XPATH, context)

    # 点击查询选项
    def get_click_input_search(tab):
        context = '(//*[@id="paramType"])[' + tab + ']/..'
        return (By.XPATH, context)

    # 查询选项列表
    def get_search_list_by_title(tab, title):
        context = '(//*[@class="rc-virtual-list"])[' + tab + ']//*[contains(@title,"' + title + '")]'
        return (By.XPATH, context)

    # 查询输入框
    def search_input(tab):
        context = '(//*[@id="paramType"])[' + tab + ']/../../../../../../../..//*[@type="text"]'
        return (By.XPATH, context)

    # 查询按钮
    def button_search(tab):
        context = '(//*[text()="Search"]/..)[' + tab + ']'
        return (By.XPATH, context)

    # 获取第一条数据的Event ID
    get_list_event_id = (By.XPATH,
                         '((//*[@class="antd4-table-tbody"])["1"]//tr[@class="antd4-table-row antd4-table-row-level-0"]/td[2]/div)[1]')

    """
        Events Detail页面
    """
    event_information_id = (By.XPATH, '//div[text()="Event ID"]/../../span[2]')

    """
        operation management | Monitoring Events
    """
    # Monitoring Events菜单
    monitoring_events_menu = (By.XPATH, '//div[text()="Monitoring Events" and @class="cre-menu-layer-2"]')
    # 查询条件选择按钮
    click_search_term = (By.XPATH, '//input[@id="queryType"]/..')
    # 查询输入框
    input_search_term = (By.XPATH, '//input[@id="queryCriteria" and @type="text"]')
    # 查询按钮
    button_search1 = (By.XPATH, '//span[text()="Search"]/..')
    # reset 按钮
    button_reset = (By.XPATH, '//span[text()="Search"]/ancestor::form[1]//span[text()="Reset"]/..')
    # 第一条数据的name值
    list_first_name = (By.XPATH, '//*[@class="antd4-table-tbody"]/tr[2]/td[2]/a')
    # 第一条数据的type值
    list_first_type = (By.XPATH, '//*[@class="antd4-table-tbody"]/tr[2]/td[3]/div')
    # 第一条数据的Monitor From值
    list_first_monitor_from = (By.XPATH, '//*[@class="antd4-table-tbody"]/tr[2]/td[4]/div')
    # 第一条数据的Notification
    list_first_Notification = (By.XPATH, '//*[@class="antd4-table-tbody"]/tr[2]/td[10]/a')

    """ 
        Monitoring Events/Detail
    """
    detail_name = (By.XPATH, '//*[@class="cre-page-container-header-panel"]//div[@class="antd4-space-item"][1]/div')
    detail_type = (By.XPATH, '//*[text()="Event Type"]/ancestor::div[1]/span[2]')
    detail_monitor_from = (By.XPATH, '//*[text()="Monitor From"]/ancestor::div[1]/span[2]')
    detail_Notification = (By.XPATH, '//*[text()="Notification Template"]/ancestor::div[1]/span[2]')
    # Trouble Shooting 按钮  //*[text()="Trouble Shooting"]
    button_trouble_shooting = (By.XPATH, '//*[text()="Trouble Shooting"]')
    # Rules & Scenarios
    button_rules = (By.XPATH, '//*[text()="Rules & Scenarios"]')
    # 关闭按钮
    button_close = (By.XPATH, '//*[@aria-label="close"]')
    # 历史 //*[text()="Event History"]
    event_history = (By.XPATH,'//*[text()="Event History"]')
    # new_event_created
    text_new_event_created = (By.XPATH,'//div[@class="antd4-timeline-item-content"]//*[text()="New Event Created"]')
    # new
    text_new = (By.XPATH,'//div[@class="antd4-timeline-item-content"]//*[text()="NEW"]')

    """
         operation management / Events
    """
    # Events菜单
    events_menu = (By.XPATH, '//div[text()="Events" and @class="cre-menu-layer-2"]')
    # 查询条件选择按钮
    click_events_search_term = (By.XPATH, '//input[@id="queryType"]/..')
    # 查询输入框
    input_events_search_term = (By.XPATH, '//input[@id="queryCriteria" and @type="text"]')
    # 查询按钮
    button_events_search = (By.XPATH, '//span[text()="Search"]/..')
    # reset 按钮
    button_events_reset = (By.XPATH, '//span[text()="Search"]/ancestor::form[1]//span[text()="Reset"]/..')
    # 触发选择时间
    click_time = (By.XPATH, '//*[@class="antd4-picker-input antd4-picker-input-active"]')
    # 时间选择
    choose_time = (By.XPATH, '//*[@class="antd4-picker-content"]//td[contains(@class,"antd4-picker-cell-in-view")]')
    # 小时，分钟，秒 选择  1,2,3
    def choose_hours_minutes(num):
        context = '//*[@class="antd4-picker-time-panel-column"][' + num + ']//div'
        return (By.XPATH,context)
    # 时间选择框向前选择
    choose_begin_time = (By.XPATH,'//*[@class="antd4-picker-header-prev-btn"]')
    # 时间选择ok按钮
    button_ok_time = (By.XPATH,'//*[@class="antd4-picker-ok"]/button')
    # 列表数据第一条数据的时间
    events_first_time = (By.XPATH,'//*[@class="antd4-table-tbody"]/tr[2]/td[7]/div')
    # 列表数据时间值 list
    events_time = (By.XPATH,'//*[@class="antd4-table-tbody"]/tr[@class="antd4-table-row antd4-table-row-level-0"]/td[7]/div')
    # sla_breach数量
    sla_breach_num = (By.XPATH,'//*[text()="SLA Breach"]/../div[1]')
    # new 数量
    new_num = (By.XPATH,'//*[text()="New"]/../div[1]')
    # re_open 数量
    re_open_num = (By.XPATH,'//*[text()="Re-Open"]/../div[1]')
    # manual_fix 数量
    manual_fix = (By.XPATH,'//*[text()="Manual Fix"]/../div[1]')
    # ignored数量
    ignored_num = (By.XPATH,'//*[text()="Ignored"]/../div[1]')
    # total 数量
    total_num = (By.XPATH,'//*[@class="antd4-pagination-total-text"]')

    # status状态选择
    status_choose = (By.XPATH, '//span[text()="Status"]/..//span[@class="anticon anticon-filter"]/..')
    # reset 按钮
    reset_point = (By.XPATH, '//*[contains(@class,"antd4-dropdown")]//span[text()="Reset"]/..')
    #reset_point = (By.XPATH, '(//span[text()="Reset"]/..)[4]')

    # OK 按钮
    ok_point = (By.XPATH, '//*[contains(@class,"antd4-dropdown")]//span[text()="OK"]')
    #ok_point = (By.XPATH, '(//button[span[text()="OK"]])[3]')

    # 根据名称选择status状态
    def select_status_by_name(status_name):
        context = '//span[text()="' + status_name + '"]/ancestor::span[@class="antd4-dropdown-menu-title-content"]'
        return (By.XPATH, context)
    # 第一条数据的 Event ID
    first_event_id = (By.XPATH,'//*[@class="antd4-table-tbody"]/tr[2]/td[1]/a')
    # 第一条数据的 status
    first_status = (By.XPATH,'//*[@class="antd4-table-tbody"]/tr[2]/td[6]/div/div[2]')


    """
        
    """
